package user_interface;

import DataAccessObject.tblConDauDAO;
import DataAccessObject.tblThanhVienDAO;
import EntityObject.tblConDauEO;
import EntityObject.tblThanhVienEO;
import java.awt.HeadlessException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public final class ConDau_UI extends javax.swing.JFrame {
    public tblConDauEO _tblConDauEO = new tblConDauEO(0, null, null, null, null, null, null , null, 0, null);
  //  public        DateFormat formatter  = new SimpleDateFormat("mm/dd/yyyy");
    public ConDau_UI(){
        initComponents();
        loadTable();
    }

    public void loadTable() {
        DefaultTableModel tableModel = new DefaultTableModel();
        Vector title = new Vector();
        title.addElement("Mã con dâu");
        title.addElement("Tên con dâu");
        title.addElement("  Tên húy");
        title.addElement("  Nơi sinh");
        title.addElement("Nơi ở hiện nay");
        title.addElement("Ngày sinh");
        title.addElement("Ngày mất");
        title.addElement("Nơi an táng");
        title.addElement("    Đời thứ");
        title.addElement("  Ghi chú");        
        tableModel.setColumnIdentifiers(title);
//     setPK_iMaCD(txtMaCD.getText());
//     setsTenCD(txtsTenCD.getText());
        _tblConDauEO.setPK_iMaCD(0);
        _tblConDauEO.setsTenCD(null);
        _tblConDauEO.setsTenHuy(null);
        _tblConDauEO.setsNoiSinh(null);
        _tblConDauEO.setsNoiOHienTai(null);
        _tblConDauEO.setsNgaySinh(null);
        _tblConDauEO.setsNgayMat(null);
        _tblConDauEO.setsNoiAnTang(null);
        _tblConDauEO.setiDoiThu(0);
        _tblConDauEO.setsGhiChu(null);
          
        
        try {
            ResultSet rs = tblConDauDAO.ConDau_SelectList(_tblConDauEO);
            while (rs.next()) {
                Vector data = new Vector();
                data.addElement(rs.getInt(1));  // Mã CD kiểu Int
                data.addElement(rs.getString(2));  // Tên CD kiểu string
                data.addElement(rs.getString(3));  // Tên CD kiểu string
                data.addElement(rs.getString(4));  // Tên CD kiểu string
                data.addElement(rs.getString(5));  // Tên CD kiểu string
                data.addElement(rs.getString(6));  // Tên CD kiểu string
                data.addElement(rs.getString(7));  // Tên CD kiểu string
                data.addElement(rs.getString(8));  // Tên CD kiểu string
                data.addElement(rs.getInt(9));  // Tên CD kiểu int                
                data.addElement(rs.getString(10));  // Tên CD kiểu string
                tableModel.addRow(data);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Lỗi Load Dữ liệu tại bảng Con Dâu:' "+e.getMessage()+ " '");
        }
        tbConDau.setModel(tableModel);
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbConDau = new javax.swing.JTable();
        btnTimKiem = new javax.swing.JButton();
        btnXoa = new javax.swing.JButton();
        btnSua = new javax.swing.JButton();
        btnThoat = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnThem = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtiDoiThu = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtsNoiSinh = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtsTenCD = new javax.swing.JTextField();
        txtsGhiChu = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtsNoiOHienTai = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        txtPK_iMaCD = new javax.swing.JTextField();
        txtsTenHuy = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        txtsNoiAnTang = new javax.swing.JTextField();
        txtsNgaySinh = new javax.swing.JTextField();
        txtsNgayMat = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tbConDau.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbConDau.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbConDauMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbConDau);

        btnTimKiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/btnSearch.png"))); // NOI18N
        btnTimKiem.setText("Tìm kiếm");
        btnTimKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTimKiemActionPerformed(evt);
            }
        });

        btnXoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/btnDelete.png"))); // NOI18N
        btnXoa.setText("Xóa");
        btnXoa.setToolTipText("");
        btnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnXoaActionPerformed(evt);
            }
        });

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/btnEdit.png"))); // NOI18N
        btnSua.setText("Sửa");
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnThoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/btnExit.png"))); // NOI18N
        btnThoat.setText("Thoát");
        btnThoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThoatActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        jLabel1.setText("Quản lý Con Dâu trong dòng họ");

        btnThem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/btnAdd.png"))); // NOI18N
        btnThem.setText("Thêm");
        btnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThemActionPerformed(evt);
            }
        });

        jLabel2.setText("Mã con dâu:");

        jLabel4.setText("Nơi sinh:");

        jLabel5.setText("Nơi ở hiện nay:");

        txtsNoiSinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtsNoiSinhActionPerformed(evt);
            }
        });

        jLabel15.setText("Đời thứ:");

        txtsGhiChu.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtsGhiChu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtsGhiChuActionPerformed(evt);
            }
        });

        jLabel3.setText("Tên con dâu:");

        jLabel16.setText("Ghi chú:");

        jLabel6.setText("Ngày sinh:");

        jLabel8.setText("Tên húy:");

        txtPK_iMaCD.setEnabled(false);
        txtPK_iMaCD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPK_iMaCDActionPerformed(evt);
            }
        });

        jLabel10.setText("Ngày mất:");

        jLabel11.setText("Nơi an táng:");

        txtsNgaySinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtsNgaySinhActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(txtsGhiChu, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(btnTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(48, 48, 48)
                        .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(62, 62, 62)
                        .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(btnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40))
            .addGroup(layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addComponent(txtsNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(66, 66, 66)
                                        .addComponent(jLabel10)
                                        .addGap(18, 18, 18)
                                        .addComponent(txtsNgayMat, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(txtsNoiOHienTai, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(txtsNoiSinh, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtsTenHuy, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtPK_iMaCD, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(63, 63, 63)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtsTenCD, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel16)
                                .addComponent(jLabel15)))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtiDoiThu, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtsNoiAnTang, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(153, 153, 153))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 806, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(19, 19, 19))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtPK_iMaCD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtsTenCD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtsTenHuy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtsNoiSinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtsNoiOHienTai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel10)
                    .addComponent(txtsNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtsNgayMat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtsNoiAnTang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtiDoiThu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtsGhiChu, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThem, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnThoat, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(171, 171, 171))
        );

        setSize(new java.awt.Dimension(870, 611));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnTimKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTimKiemActionPerformed
        JOptionPane.showMessageDialog(this, "Chức năng này đang xây dựng");
    }//GEN-LAST:event_btnTimKiemActionPerformed

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        _tblConDauEO.setPK_iMaCD(Integer.parseInt(txtPK_iMaCD.getText()));
        _tblConDauEO.setsTenCD(txtsTenCD.getText());
        _tblConDauEO.setsTenHuy(txtsTenHuy.getText());
        _tblConDauEO.setsNoiSinh(txtsNoiSinh.getText());
        _tblConDauEO.setsNoiOHienTai(txtsNoiOHienTai.getText());
        _tblConDauEO.setsNgaySinh(txtsNgaySinh.getText());
        _tblConDauEO.setsNgayMat(txtsNgayMat.getText());
        _tblConDauEO.setsNoiAnTang(txtsNoiAnTang.getText());
        _tblConDauEO.setiDoiThu(Integer.parseInt(txtiDoiThu.getText()));
        _tblConDauEO.setsGhiChu(txtsGhiChu.getText());
        
        try {
            int dialogResult = JOptionPane.showConfirmDialog(this, "Bạn muốn sửa bản ghi ko?", "Gia phả dòng họ",JOptionPane.YES_NO_OPTION);
            if(dialogResult==0){
                try {
                    if(tblConDauDAO.ConDau_Update(_tblConDauEO) == true){
                        JOptionPane.showMessageDialog(this, "Sửa thành công");
                    }
                    else{
                        JOptionPane.showMessageDialog(this, "Lỗi sửa dữ liệu");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ConDau_UI.class.getName()).log(Level.SEVERE, null, ex);
                }
                loadTable();  
            }
        }
        catch (HeadlessException e) {
            JOptionPane.showMessageDialog(this, "Lỗi sửa dữ liệu");
        }
    }//GEN-LAST:event_btnSuaActionPerformed

    private void btnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnXoaActionPerformed
        _tblConDauEO.setPK_iMaCD(Integer.parseInt(txtPK_iMaCD.getText()));
        try {
            int dialogResult = JOptionPane.showConfirmDialog(this, "Bạn muốn xóa bản ghi ko?", "Gia phả dòng họ",JOptionPane.YES_NO_OPTION);
            if(dialogResult==0){
                try {
                    if(tblConDauDAO.ConDau_Delete(_tblConDauEO) == true){
                        JOptionPane.showMessageDialog(this, "Xóa thành công");
                    }
                    else{
                        JOptionPane.showMessageDialog(this, "Lỗi xóa dữ liệu");
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(ConDau_UI.class.getName()).log(Level.SEVERE, null, ex);
                }
                loadTable();  
            }
        }
        catch (HeadlessException e) {
            JOptionPane.showMessageDialog(this, "Lỗi xóa dữ liệu");
        }
    }//GEN-LAST:event_btnXoaActionPerformed

    private void btnThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThoatActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btnThoatActionPerformed

    private void btnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThemActionPerformed

    //    _tblConDauEO.setPK_iMaCD(Integer.parseInt(txtPK_iMaCD.getText()));
        _tblConDauEO.setsTenCD(txtsTenCD.getText());
        _tblConDauEO.setsTenHuy(txtsTenHuy.getText());
        _tblConDauEO.setsNoiSinh(txtsNoiSinh.getText());
        _tblConDauEO.setsNoiOHienTai(txtsNoiOHienTai.getText());
        _tblConDauEO.setsNgaySinh(txtsNgaySinh.getText());
        _tblConDauEO.setsNgayMat(txtsNgayMat.getText());
        _tblConDauEO.setsNoiAnTang(txtsNoiAnTang.getText());
        _tblConDauEO.setiDoiThu(Integer.parseInt(txtiDoiThu.getText()));
        _tblConDauEO.setsGhiChu(txtsGhiChu.getText());
       
        try {
            if(tblConDauDAO.ConDau_Insert(_tblConDauEO) == true){
                JOptionPane.showMessageDialog(this, "Thêm thành công");
            }
            else{
                JOptionPane.showMessageDialog(this, "Lỗi thêm dữ liệu");
            }
            loadTable();
        }
        catch (SQLException | HeadlessException e) {
            JOptionPane.showMessageDialog(this, "Lỗi thêm dữ liệu");
        }
    }//GEN-LAST:event_btnThemActionPerformed

    private void txtsGhiChuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtsGhiChuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtsGhiChuActionPerformed

    private void txtPK_iMaCDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPK_iMaCDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPK_iMaCDActionPerformed

    private void txtsNgaySinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtsNgaySinhActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtsNgaySinhActionPerformed

    private void tbConDauMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbConDauMouseClicked
        // TODO add your handling code here:             
                
        int index = tbConDau.getSelectedRow();
      txtPK_iMaCD.setText(String.valueOf(tbConDau.getValueAt(index, 0)));
      tblConDauEO objtblConDauEO = new tblConDauEO(0, null, null, null, null, null, null , null, 0, null);
      objtblConDauEO.setPK_iMaCD(Integer.parseInt(txtPK_iMaCD.getText()));
        try {
            ResultSet rs = tblConDauDAO.ConDau_SelectItem(objtblConDauEO);
            while (rs.next()) {
                
                txtsTenCD.setText(String.valueOf(rs.getString(2)));  // Mã CD kiểu String
                txtsTenHuy.setText(String.valueOf(rs.getString(3)));
                txtsNoiSinh.setText(String.valueOf(rs.getString(4)));
                txtsNoiOHienTai.setText(String.valueOf(rs.getString(5)));
                txtsNgaySinh.setText(String.valueOf(rs.getString(6)));
                if(rs.getString(7) == null){
                txtsNgayMat.setText("");
                }
                else{
                txtsNgayMat.setText(String.valueOf(rs.getString(7)));
                }    
                if(rs.getString(8) == null){
                txtsNoiAnTang.setText("");
                }
                else{
                txtsNoiAnTang.setText(String.valueOf(rs.getString(8)));
                }
                txtiDoiThu.setText(String.valueOf(rs.getString(9)));
                if(rs.getString(10) == null){
                txtsNoiAnTang.setText("");
                }
                else{
                txtsGhiChu.setText(String.valueOf(rs.getString(10)));
                }                       
            }
        } catch (SQLException e) {
            JOptionPane.showMessageDialog(this, "Lỗi Load Dữ liệu tại bảng Thành viên:' "+e.getMessage()+ " '");
        }
    }//GEN-LAST:event_tbConDauMouseClicked

    private void txtsNoiSinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtsNoiSinhActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtsNoiSinhActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ConDau_UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ConDau_UI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSua;
    private javax.swing.JButton btnThem;
    private javax.swing.JButton btnThoat;
    private javax.swing.JButton btnTimKiem;
    private javax.swing.JButton btnXoa;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbConDau;
    private javax.swing.JTextField txtPK_iMaCD;
    private javax.swing.JTextField txtiDoiThu;
    private javax.swing.JTextField txtsGhiChu;
    private javax.swing.JTextField txtsNgayMat;
    private javax.swing.JTextField txtsNgaySinh;
    private javax.swing.JTextField txtsNoiAnTang;
    private javax.swing.JTextField txtsNoiOHienTai;
    private javax.swing.JTextField txtsNoiSinh;
    private javax.swing.JTextField txtsTenCD;
    private javax.swing.JTextField txtsTenHuy;
    // End of variables declaration//GEN-END:variables

   // private static class txtsNgaymat {

    //    public txtsNgaymat() {
    //    }
 //   }
}
